home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Sierp3Form
- Caption = "Sierpinski Gasket"
- ClientHeight = 4335
- ClientLeft = 2280
- ClientTop = 1185
- ClientWidth = 5070
- Height = 5025
- Left = 2220
- LinkTopic = "Form1"
- ScaleHeight = 289
- ScaleMode = 3 'Pixel
- ScaleWidth = 338
- Top = 555
- Width = 5190
- Begin VB.TextBox LevelText
- Height = 285
- Left = 600
- MaxLength = 3
- TabIndex = 0
- Text = "5"
- Top = 0
- Width = 375
- End
- Begin VB.PictureBox Canvas
- AutoRedraw = -1 'True
- Height = 4335
- Left = 1080
- ScaleHeight = 285
- ScaleMode = 3 'Pixel
- ScaleWidth = 261
- TabIndex = 3
- Top = 0
- Width = 3975
- End
- Begin VB.CommandButton CmdGo
- Caption = "Go"
- Default = -1 'True
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 480
- Width = 735
- End
- Begin VB.Label Label1
- Caption = "Level"
- Height = 255
- Index = 0
- Left = 0
- TabIndex = 2
- Top = 0
- Width = 495
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "Sierp3Form"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Const PI = 3.14159
- Dim TheLevel As Integer
- ' Maximum space the curve can take up.
- Dim TotalLength As Single
- Dim StepLength As Single
- Dim StartX As Integer
- Dim StartY As Integer
- ' ************************************************
- ' Draw a gasket-like Sierpinski curve.
- ' ************************************************
- Sub Sierp(level As Integer, theta As Single, dist As Single, turn As Single)
- If level > 0 Then
- Sierp level - 1, theta + turn, dist / 2, -turn
- Sierp level - 1, theta, dist / 2, turn
- Sierp level - 1, theta - turn, dist / 2, -turn
- Else
- Canvas.Line -Step(dist * Cos(theta), dist * Sin(theta))
- End If
- End Sub
- Sub GetParameters()
- If Not IsNumeric(LevelText.Text) Then _
- LevelText.Text = "5"
- TheLevel = CInt(LevelText.Text)
- End Sub
- Private Sub CmdGo_Click()
- Dim i As Integer
- MousePointer = vbHourglass
- DoEvents
- ' Get the parameters.
- GetParameters
- ' Draw the curve.
- Canvas.Cls
- Canvas.CurrentX = StartX
- Canvas.CurrentY = StartY
- Sierp TheLevel, 0, TotalLength, -PI / 3
- MousePointer = vbDefault
- End Sub
- Private Sub Form_Resize()
- Canvas.Move Canvas.Left, 0, _
- ScaleWidth - Canvas.Left, ScaleHeight - 1
- ' See how big we can make the curve.
- If Canvas.ScaleHeight < Canvas.ScaleWidth Then
- TotalLength = 0.9 * Canvas.ScaleHeight
- Else
- TotalLength = 0.9 * Canvas.ScaleWidth
- End If
- ' Compute the upper left corner.
- StartX = Canvas.ScaleWidth * 0.05
- StartY = Canvas.ScaleHeight * 0.95
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-